home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / Yaroze / UploadSrc / tools.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-09  |  2.8 KB  |  136 lines

  1. /*
  2.  * NAME
  3.  *   tools.c -17-May-97 18:44:43
  4.  *
  5.  * AUTHOR
  6.  *   Jon Rocatis
  7.  *
  8.  * DESCRIPTION
  9.  *   Contains some helper functions. Nothing serious.
  10.  *
  11.  */
  12.  
  13. #include <ctype.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <exec/types.h>
  17. #include <devices/serial.h>
  18. #include <proto/all.h>
  19. #include <time.h>
  20. #include <string.h>
  21.  
  22. #include "upload_protos.h"
  23. #include "serial_protos.h"
  24. #include "tools_protos.h"
  25. #include "myecoff.h"
  26. #include "upload.h"
  27.  
  28. /*
  29.  * NAME
  30.  *   DisplayBuffer
  31.  *
  32.  * FUNCTION
  33.  *   Displays some bytes from the serial ring buffer
  34.  *
  35.  */
  36.  
  37. void DisplayBuffer()
  38. {
  39.   LONG y,x;
  40.  
  41.     for ( y = 0; y < 8; y++ )
  42.     {
  43.       printf("%08x: ", y*16);
  44.       
  45.       for ( x = 0; x < 16; x++ )
  46.       {
  47.         printf("%02x ", buffer[y*16+x]);
  48.       }
  49.  
  50.       for ( x = 0; x < 16; x++ )
  51.       {
  52.         if (isprint(buffer[y*16+x]))
  53.           printf("%c", buffer[y*16+x]);
  54.         else
  55.           printf(".");
  56.       }
  57.       printf("\n");
  58.     }
  59. }
  60.  
  61. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  62.  
  63. void DisplaySectionInfo( struct Section *s )
  64. {
  65.     printf( "Name:     %s\n",         s->name );
  66.     printf( "LoadAddr: $%08x - $%08x\n", s->loadAddr, s->loadAddr + s->size );
  67.     printf( "Size:     $%08x (%d)\n", s->size, s->size );
  68.     printf( "FilePos:  $%08x\n",      s->fpos );
  69.     printf( "\n" );
  70. }
  71.  
  72. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  73.  
  74. /*
  75.  * NAME
  76.  *   GetFileSize
  77.  *
  78.  * FUNCTION
  79.  *   Gets the size of a file in bytes
  80.  *
  81.  * INPUT
  82.  *   fname - filename
  83.  *
  84.  * RESULT
  85.  *   size or -1 if failure
  86.  *
  87.  */
  88.  
  89. LONG GetFileSize( char *fname )
  90. {
  91.   struct FileInfoBlock *fib;
  92.   BPTR   fh;
  93.   LONG   size = -1;
  94.  
  95.     if (fib = (struct FileInfoBlock *)AllocDosObject(DOS_FIB, NULL))
  96.     {
  97.       if (fh = Open( fname, MODE_OLDFILE) )
  98.       {
  99.         ExamineFH(fh,fib);
  100.         Close(fh);
  101.         size = fib->fib_Size;
  102.       }
  103.       FreeDosObject(DOS_FIB, fib);
  104.     }
  105.     return(size);
  106. }
  107.  
  108. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  109.  
  110. int GetBaudRate()
  111. {
  112.   FILE *fp;
  113.   char  buffer[80];
  114.   int   baudrate;
  115.   static int legal[] = {2400,4800,9600,19200,38400,57600,76800,96000,115200,-1};
  116.   LONG  idx;
  117.   
  118.     if ( fp = fopen( "PROGDIR:baudrate.txt", "r" ) )
  119.     {
  120.       fgets( buffer, sizeof(buffer), fp );
  121.       baudrate = atoi( buffer );
  122.       fclose(fp);
  123.       
  124.       idx = 0;
  125.       while (legal[idx] != -1)
  126.       {
  127.         if ( legal[idx++] == baudrate )
  128.           return( baudrate );
  129.       }
  130.     }
  131.     return(-1);
  132. }
  133.  
  134. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  135.  
  136.